Skip to main content

All Questions

Tagged with
0votes
1answer
89views

Simple Bash script Nested while and for loops while reading from a text file

I have the following bash script which works fine but only goes through the for loop once! #!/bin/bash csv_file="regime.csv" ratio=(0.2 0.4 0.6 0.8) while IFS=',' read -r col1 col2 col3 ...
Karen Tabar's user avatar
0votes
1answer
58views

For loop inside While loop not breaking - Matlab

Flag = 0; while Flag == 0 for x = 1:10 if x == 3 Flag = 1; end % end: if end % end; for end % end: while Can anyone tell me why the while loop condition is not ...
Alexander Savadelis's user avatar
-6votes
2answers
68views

Loop with 'for' [closed]

This is a Python 3 question for loops using 'for' Why does the print(num-1) still execute at range 4? In my mind when range is 4 it should skip print(num-1) and go straight to else: print(num). for ...
Jay B.'s user avatar
1vote
5answers
101views

Bash Script While Loop from two files [closed]

Im trying to do the below: file1: x.x.x.5 x.x.x.6 file2: router switch Trying to loop through both files to create two additional files each name in file2 as: ping_router.sh sudo /sbin/mtr -rn -c 30 -...
D' go's user avatar
-2votes
1answer
50views

Increment arithmetic in TCL

I am trying to increment the output by 2 (every line increment by 2) while reading in a file. Here is my code: Input.txt: green yellow grey purple SCRIPT: set infile [open "input.txt" r] ...
Chang's user avatar
0votes
2answers
61views

Or in While loops in python [duplicate]

I can get the Fahrenheit to Celcius side working but not the other way around # converts between C and F # conversion = C * 9/5 +32 = F unit = input("is the temperature in Celsius or ...
Ihsan Ali's user avatar
2votes
1answer
98views

R - The for loop may have bug while the acc it work with is a function. But why?

The issue There is a case such as this, acc = \ (a) \ (b) base::list(a = a, b = b) for (x in c("A","B")) {acc = acc(x)} acc It returns: $a [1] "B" $b [1] "B" ...
ypa y yhm's user avatar
0votes
2answers
76views

Why is the "for" cycle not creating multiple files?

Why is this code not creating several files? ofstream should create a file when it encounters a file name that doesn't exist. However, for some reason, even though the names are different, it creates ...
Фёдор Руденко's user avatar
-3votes
2answers
161views

any differences between "while(true) { code }" and "for(int i = 0; i < n; i++) { code }" [closed]

supposed I have this code while (true) { // do things if (condition) break; } if I can always determine that the while loop stops after less than n times during runtime, should I write this ...
Le_Square's user avatar
-1votes
2answers
93views

Python using a for with a while loop

Currently I have this for word in words: print(word) but now i want to introduce a while loop, to only execute that as long as an image (spinner.png) is located on the screen. like this while True:...
sinyce's user avatar
-4votes
1answer
110views

Counting the number of occurrences of a number in a list without using loops (for or while) [closed]

For example there is a list like A = [7 , 77 , 777 , 717]. I want to count the number of occurrences of the digit 7 in the list, but without using any loops. It should output 8. (7 occurred 8 times). ...
Kian Mashayekhi's user avatar
-2votes
3answers
105views

Given an array of numbers(arr) and the length of the array(n) as arguments, how do you create a tribonacci sequence?

Consider: function tribonacci(arr, n){ let sum = 0; for(let i= arr.length-1; i > arr.length-4; i--){ sum += arr[i] } while(arr.length < n){ arr.push(sum); }...
Decodeme's user avatar
0votes
1answer
43views

How to to loop through portion of Array in Swift

I want to loop through a portion of an Array in Swift, not the entire array based on the index. The array is coming from an API so I don't know the number of elements in advance. For example for the ...
user6631314's user avatar
-3votes
2answers
59views

The difference between a "for" loop and a "while" loop [duplicate]

This is more of a question to aid my understanding as I learn python. I am working my way through an exercise book and the following challenge was given: Start with a copy of your program from ...
Callilou's user avatar
0votes
0answers
11views

Filling and Substituting in R Loop

I organized a loop to calculate a new bus fleet within a budget. BUS TYPE: PADRON, PRICE: 1KK; BUS TYPE: MEDIO, PRICE: 800k. In this example I am allocating the budget to new types of PADRON, ...
silvasilva's user avatar

153050per page
close